package com.neusoft.neuiotms.dcom.converter.change;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.change.ChangeImplementationAttachmentDTO;
import com.neusoft.neuiotms.dcom.model.change.ChangeImplementationAttachment;
import com.neusoft.neuiotms.dcom.repository.change.ChangeImplementationAttachmentRepository;

@Component
public class ChangeImplementationAttachmentConverter
        extends AbstractConverter<ChangeImplementationAttachment, ChangeImplementationAttachmentDTO> {

    @Autowired
    private ChangeImplementationAttachmentRepository changeImplementationAttachmentRepository;

    @Override
    public ChangeImplementationAttachment toModel(final ChangeImplementationAttachmentDTO dto) {
        ChangeImplementationAttachment model;
        if (dto.isNew()) {
            model = new ChangeImplementationAttachment();
        } else {
            model = this.changeImplementationAttachmentRepository.getOne(dto.getId());
        }
        model.setFsId(dto.getFsId());
        model.setName(dto.getName());
        return model;
    }

    @Override
    public ChangeImplementationAttachmentDTO toDTO(final ChangeImplementationAttachment model,
            final boolean forListView) {
        final ChangeImplementationAttachmentDTO dto = new ChangeImplementationAttachmentDTO();
        dto.setFsId(model.getFsId());
        dto.setId(model.getId());
        dto.setName(model.getName());
        return dto;
    }
}
